<!--
  author: tangcheng_cd
  create by: 2018/5/25
  descr: 菜单树形表格
-->
<template>
  <div>
    <v-tree-menu :columns="cols"
                 :rows="rows"
                 :defaultExpandAll="false"
                 :props="treeProps"
                 v-loading="menuTableLoading"
                 lazy
                 ref="vtm"
                 :load="loadMenuTreeNodeData">
    </v-tree-menu>
  </div>
</template>
<script type="text/ecmascript-6">
  //  需要导入的路径
  import VTreeMenu from '../../../components/VTreeMenu/VTreeMenu'
  import {sysNo} from '../../../dict/dict.js'
  import api from '../../../api/url'
  import ajax from '../../../api/ajax'
  export default {
    name: 'menu-tree-grid',
    components: {
      VTreeMenu
    },
    props: {
      columns: Array
    },
    data () {
      return {
        // 列属性配置
        cols: [
          {
            label: '菜单名称',
            name: 'name',
            index: 'name'
          }, {
            label: '菜单类型',
            name: 'type',
            index: 'type',
            holder: 'radio-group',
            width: '200px',
            items: [{
              label: '目录',
              value: 'DIR'
            }, {
              label: '功能按钮',
              value: 'FUNCTION_POINT'
            }, {
              label: '菜单',
              value: 'MENU'
            }]
          }, {
            label: '菜单描述',
            name: 'remark',
            index: 'remark',
            width: '200px'
          }, /* {
            label: '资源统一标识',
            name: 'resourceCode',
            index: 'resourceCode',
            width: '200px'
          }, */ {
            label: '资源地址',
            name: 'url',
            index: 'url',
            width: '350px'
          }
        ],
        // 数据
        rows: [],
        // 树配置
        treeProps: {
          children: 'children',
          label: 'label',
          isLeaf: 'leaf'
        },
        menuTableLoading: false
      }
    },
    methods: {
      loadMenuTreeNodeData (node, resolve) {
        let postData
        if (node.level === 0) {
          postData = {
            sysNo: sysNo,
            id: 0
          }
        } else {
          // console.info(node)
          postData = {
            sysNo: node.data.sysNo,
            id: node.data.id
          }
        }
        this.menuTableLoading = true
        ajax.post(api.GET_MENU_CHILDREN, postData).then(res => {
          resolve(res.data)
          this.menuTableLoading = false
        }).catch(e => {
          console.error('获取菜单树发生错误！')
        })
      },
      refreshTreeData () {
        console.info(this)
      },
      getCurrentNode () {
        return this.$refs.vtm.getCurrentNode()
      }
    },
    created () {
      if (this.columns) {
        this.cols = this.columns
      }
    }
  }
</script>
